import { _decorator, Component, Layers, Node, resources, Sprite, SpriteFrame, UITransform } from 'cc';
import { TILE_TYPE_ENUM } from '../../Enum';
const { ccclass, property } = _decorator;

export const TILE_WEIGHT = 55
export const TILE_HEIGHT = 55

@ccclass('TileItem')
export class TileItem extends Component {

  movable: boolean = false
  turnable: boolean = false

  init(spriteFrame : SpriteFrame, i: number, j: number, type: TILE_TYPE_ENUM){
    const sprite = this.addComponent(Sprite)
    sprite.spriteFrame = spriteFrame
    const uiTranseform = this.getComponent(UITransform)
    uiTranseform.setContentSize(TILE_WEIGHT, TILE_HEIGHT)
    this.node.setPosition(i * TILE_WEIGHT, -j * TILE_HEIGHT)

    if (this.isWall(type)) {
      this.movable = false
      this.turnable = false
    } else if (this.isCliff(type)){
      this.movable = false
      this.turnable = true
    } else if (this.isFloor(type)) {
      this.movable = true
      this.turnable = true
    }
  }

    isWall(type: TILE_TYPE_ENUM) {
      return type == TILE_TYPE_ENUM.WALL_COLUMN ||
        type == TILE_TYPE_ENUM.WALL_LEFT_BOTTOM ||
        type == TILE_TYPE_ENUM.WALL_LEFT_TOP ||
        type == TILE_TYPE_ENUM.WALL_RIGHT_BOTTOM ||
        type == TILE_TYPE_ENUM.WALL_RIGHT_TOP ||
        type == TILE_TYPE_ENUM.WALL_ROW
    }

    isCliff(type: TILE_TYPE_ENUM) {
      return type == TILE_TYPE_ENUM.CLIFF_CENTER ||
        type == TILE_TYPE_ENUM.CLIFF_LEFT ||
        type == TILE_TYPE_ENUM.CLIFF_RIGHT
    }

    isFloor(type: TILE_TYPE_ENUM) {
      return type == TILE_TYPE_ENUM.FLOOR
    }

  }




